#include <iostream>

#include  <pthread.h>

using namespace std;

//对互斥锁进行封装

//自己不维护锁，外部传入
class Mutex
{
public:
    Mutex(pthread_mutex_t* mutex)
        :_pmutex(mutex)
    {
        
    }

    ~Mutex()
    {
        
    }

    void lock()
    {
        pthread_mutex_lock(_pmutex);
    }

    void unlock()
    {
        pthread_mutex_unlock(_pmutex);
    }
public:
    pthread_mutex_t* _pmutex;
};


class LockGuard
{
public:
    LockGuard(pthread_mutex_t* mutex)
        :_mutex(mutex)
    {
        _mutex.lock();
    }

    ~LockGuard()
    {
        _mutex.unlock();
    }
public:
    Mutex _mutex;
};